
import { getRouters } from '@/api';
<template>
  <div class="list_container flex both-100">
    <Breadcrumb :title="pageTitle" />
    <div class="content_container">
      <!-- 搜索模块 -->
      <el-form ref="searchMap" :inline="true" :model="searchMap" class="serach_wrapper flex-space-between">
        <div class="search">
          <el-form-item prop="dictName" size="small">
            <el-input v-model="searchMap.dictName" placeholder="请输入字典名称"></el-input>
          </el-form-item>
          <el-form-item prop="dictType" size="small">
            <el-input v-model="searchMap.dictType" placeholder="请输入字典类型"></el-input>
          </el-form-item>
          <el-form-item prop="status" style="width: 220px" size="small">
            <el-select v-model="selectValue" placeholder="字典状态">
              <el-option v-for="item in searchMap.status" :key="item.value" :label="item.label" :value="item.label"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="personnelCreateTime" size="small">
            <el-date-picker v-model="searchMap.personnelCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
          <el-form-item class="flex" size="small">
            <el-button @click="handleSearch()" class="btn_primary">查询</el-button>
            <el-button @click="handleReset()" class="btn_cancel">重置</el-button>
          </el-form-item>
        </div>
        <div class="edit">
          <el-form-item class="flex">
            <el-button @click="handleAdd()" class="btn_primary" icon="el-icon-plus">
              新增
            </el-button>
            <!-- <el-button @click="handleExport()" disabled class="btn_primary" icon="el-icon-download">
                            导出
                        </el-button> -->
            <!-- <el-button @click="handleRefreshCache()" class="btn_ghost__danger" icon="el-icon-refresh">
                            刷新缓存
                        </el-button> -->
          </el-form-item>
        </div>
      </el-form>
      <!-- 搜索模块over -->

      <!-- 表格模块 -->
      <div class="table_container">
        <el-table :data="dictList" stripe class="per_table" style="width: 100%" v-loading="loading">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="字典编号" align="center" prop="dictId" />
          <el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
          <el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span @click="clickDictType(scope.row.dictId)" class="link">{{ scope.row.dictType }}</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 表格模块over -->

      <!-- 分页 -->
      <pagination v-show="total > 0" :total="total" :page.sync="searchMap.pageNum" :limit.sync="searchMap.pageSize" @change="getList"></pagination>
      <!-- 分页over -->

      <div class="dialog_content">
        <el-dialog class="m_dialog" title="弹框" :visible.sync="dialogVisible" width="800" append-to-body :close-on-click-modal="false">
          <el-form ref="form" :model="formModel" :rules="rules" label-width="80px">
            <el-form-item label="字典名称" prop="dictName">
              <el-input v-model="formModel.dictName" placeholder="请输入字典名称" />
            </el-form-item>
            <el-form-item label="字典类型" prop="dictType">
              <el-input v-model="formModel.dictType" placeholder="请输入字典类型" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="formModel.status">
                <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="formModel.remark" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="userDialogVisible = false" class="btn_cancel">取 消</el-button>
            <el-button type="primary" @click="submitForm" class="btn_primary">确 定</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
  
<script>
import Breadcrumb from '@/components/Breadcrumb'
import CustomForm from '@/components/CustomForm'
import BaseRadioGroup from '@/components/BaseForm/BaseRadioGroup.vue'
import { listType, getType, delType, addType, updateType, refreshCache } from '@/api';
export default {
  name: 'dict',
  dicts: ['sys_normal_disable'],
  components: {
    CustomForm,
    BaseRadioGroup,
    Breadcrumb,

  },
  data () {

    return {
      // 加载状态
      loading: true,
      // 搜索条件
      searchMap: {
        pageNum: 1, // 当前页
        pageSize: 10,  // 默认条数
        dictName: undefined,
        dictType: undefined,
        deptId: undefined
      },
      selectValue: "",
      // 角色列表
      dictList: [],
      // 总条数
      total: 0,
      // 是否打开弹窗
      dialogVisible: false,
      // 提交表单数据
      formModel: {},
      // 表单校验
      rules: {
        dictName: [
          { required: true, message: "字典名称不能为空", trigger: "blur" }
        ],
        dictType: [
          { required: true, message: "字典类型不能为空", trigger: "blur" }
        ]
      }

    }

  },
  created () {
    this.getList()
  },

  computed: {
    pageTitle () {
      return '字典管理'
    }
  },
  methods: {
    getList () {
      this.loading = true
      listType(this.searchMap).then(res => {
        this.dictList = res.rows
        this.total = res.total
        this.loading = false
      })
    },

    //重置搜索栏数据
    handleReset () {
      this.$refs['searchMap'].resetFields()
      this.handleSearch()
    },
    // 新增字典
    handleAdd () {
      this.resetForm()
      this.dialogVisible = true
      this.title = '添加'
    },
    // 修改字典
    handleEdit (row) {
      const dictId = row.dictId || this.ids
      getType(dictId).then(res => {
        this.formModel = res.data;
        this.dialogVisible = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.formModel.dictId != undefined) {
            updateType(this.formModel).then(res => {
              if (200 === res.code) {
                this.$message.success("修改成功");
                this.dialogVisible = false;
                this.getList();
              }
            });
          } else {
            addType(this.formModel).then(res => {
              if (200 === res.code) {
                this.$message.success("添加成功");
                this.dialogVisible = false;
                this.getList();
              }

            });
          }
        }
      });
    },
    // 删除字典
    handleDelete (row) {
      const dictIds = row.dictId || this.ids;
      this.$confirm('是否确认删除字典编号为"' + dictIds + '"的数据项？').then(function () {
        return delType(dictIds);
      }).then(() => {
        this.getList();
        this.$message.success("删除成功");
      })
    },
    // 导出字典
    handleExport () {

    },
    // 刷新缓存
    handleRefreshCache () {

    },
    // 表格搜索
    handleSearch () {
      this.searchMap.pageNum = 1;
      this.getList();

    },
    // 重置表单数据
    resetForm () {
      this.$nextTick(() => {
        this.$refs['form'].resetFields()
        this.formModel = {
          dictId: undefined,
          dictName: undefined,
          dictType: undefined,
          status: "0",
          remark: undefined
        }
      })
    },
    clickDictType(data) {
      const dictId = data || 0;
      this.$router.push({
        path: 'dictData',
        query: {
          dictId: dictId
        }
      });
    }
  }
}
</script>
  
<style lang="less" scoped>
.list_container {
  flex-direction: column;
  background: url("@/assets/images/home/content.png") no-repeat;
  background-size: cover;

  .content_container {
    padding: 15px 20px;
    overflow-y: scroll;
  }

  .table_container {
    margin-bottom: 25px;
    .link {
      color: #409eff;
      cursor: pointer;
    }
  }

  .pagination_container {
    display: flex;
    justify-content: space-between;
    height: 32px;
  }
}
</style>